#include<bits/stdc++.h>
using namespace std;
const int maxn=305;
int n,p[maxn],f[maxn][maxn][maxn];
int dfs(int l,int r,int x)
{
    if(f[l][r][x]!=-1) return f[l][r][x];
    if(l==r) return f[l][r][x]=(p[l]!=x);
    int ret=1e9,y=x+r-l;
    ret=min(ret,dfs(l,r-1,x+1)+(p[r]!=x));
    ret=min(ret,dfs(l,r-1,x)+(p[r]!=y));
    ret=min(ret,dfs(l+1,r,x+1)+(p[l]!=x));
    ret=min(ret,dfs(l+1,r,x)+(p[l]!=y));
    return f[l][r][x]=ret;
}
int main()
{
    freopen("build.in","r",stdin);
    freopen("build.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    memset(f,-1,sizeof(f));
    cin>>n;
    for(int i=1;i<=n;i++) cin>>p[i];
    cout<<dfs(1,n,1)<<'\n';
    return 0;
}
